﻿using AppSocketModel;
using System;
using System.Collections.Generic;
using System.Text;

namespace AppSocketControl.Relay
{
    public class RelayDeviceDictionary
    {
        public static Dictionary<string, int> ImeiDict = new Dictionary<string, int>(); //Dict<IMEI,CompanyId>
        public static KafakaProducer kafakaProducer = new KafakaProducer();

        static RelayDeviceDictionary()
        {

        }


        #region   重置数据
        public static void Reset(RelayDto relayDto)
        {
            ClearDict(relayDto.CompanyId);
            AddDict(relayDto.ImeiList, relayDto.CompanyId);
        }


        public static void ClearDict(int companyId)
        {           
            List<string> keyList = new List<string>();
            foreach (var item in ImeiDict)
            {
                if (item.Value == companyId)
                    keyList.Add(item.Key);
            }
            for (int i = 0; i < keyList.Count; i++)
            {
                ImeiDict.Remove(keyList[i]);
            }
        }


        private static void AddDict(List<string> imeiList,int companyId)
        {
            foreach (var item in imeiList)
            {
                ImeiDict.TryAdd(item, companyId);
            }
        }
        #endregion
    }
}
